var ws,cur_page;
var searched = 0;
var app = angular.module('app',[]);
app.controller('my_controller',function($scope,$http){
	$scope.searchAll = function(){
		searched = 'a';
		plus.nativeUI.showWaiting('搜索中');
		var text_val = $('#search_all').val();
		if(text_val== ''){
			plus.nativeUI.closeWaiting();
			mui.toast('请输入搜索内容');
			return;
		}
		
		$http({
			method:'post',
			url:apiRoot,
			data:{
				action:'User.searchUserAndGoodsAndNote',
				page:1,
				content:text_val
			}
		}).then(function success(result){
			console.log(JSON.stringify(result.data.data));
			$('#null_searched').css({'display':'none'}); //点击搜索了，隐藏"没有搜索内容"
			plus.nativeUI.closeWaiting();
			var info = result.data.data;
			$.each(info.user, function(key,vo) {
				info.user[key].icon = getAvatar(vo.icon);
			});
			$scope.user = info.user;
			$scope.goods = info.goods;
			$scope.notes = info.note;
			console.log($scope.user.length);
			console.log($scope.goods.length);
			console.log($scope.notes.length);
			//判断搜索结果
			if($scope.user.length == 0  && $scope.goods.length == 0 && $scope.notes.length == 0){
				$scope.no_result = 1;
			} else {
				$scope.no_result = 0;
			}
			
		},function errorFunction(e){
			plus.closeWaiting();
			console.log(JSON.stringify(e));
		})
	}
	
	//用户》》》》个人主页
	$scope.icon_sub =function(id,img,nick){
		plus.webview.create('honer_page.html', 'honer_page.html',{},{icon_id:id,icon_img:img,icon_name:nick}).show('pop-in');
	}
	
	//商品》》》》商品详情页
	$scope.obtainId=function(uid,type,id){
		console.log(id+"####"+type);
		plus.nativeUI.showWaiting('加载中...');
		plus.webview.create('goods_detail.html', 'goods_detail.html',{},{gUid:uid,type:type,gId:id}).show('pop-in');
		plus.nativeUI.closeWaiting();          
	}
	//图文》》》》图文内容
	$scope.viewMidea=function(uid,type,id){
		plus.nativeUI.showWaiting('加载中...');
		plus.webview.create('view_detail.html', 'view_detail.html',{},{noteUid:uid,type:type,noteId:id}).show('pop-in');   
		plus.nativeUI.closeWaiting();
	}
})

document.addEventListener('plusready',function(){
	ws = plus.webview.currentWebview();
	appElement = document.querySelector('[ng-controller=my_controller]');
	$scope = angular.element(appElement).scope();
	
})


